<?php
	require_once("System/Kernel/template.class.php");
	require_once("System/Kernel/functions.php");
	require_once("System/Security/settings.php");
	
	if(file_exists("./System/Languages/".USE_LANG."/")){
		$language = simplexml_load_file("./System/Languages/".USE_LANG."/strings.xml");
		require_once("./System/Languages/".USE_LANG."/arrays.php");
	}
	
	$template = new Template();
	$template->_template_read("./Applications/monalisa/Templates/exposition3.html");
	
	$template->_template_assign("CAPTION_EXPO1", (string)$language->common->value_43);
	$template->_template_assign("CAPTION_EXPO4", (string)$language->common->value_31);
	$template->_template_assign("CAPTION_EXPO5", (string)$language->common->value_30);
	$template->_template_assign("CAPTION_EXPO6", (string)$language->common->value_7);
	$template->_template_assign("CAPTION_EXPO7", (string)$language->common->value_8);
	$template->_template_assign("CAPTION_EXPO8", (string)$language->common->value_9);
	$template->_template_assign("CAPTION_EXPO9", (string)$language->common->value_10);
	
	$template->_template_assign("DESIGN", DESIGN);
	
	$expo = $_GET["expo"];
	oyster_log("MSG", "Ausstellung wurde aufgerufen ($expo) von ".$_SERVER["REMOTE_ADDR"].".", "MonaLisa Exposition");
	if (file_exists("./Applications/monalisa/Expositions/".$expo.".expo")){
		$expo_file = sqlite_open("./Applications/monalisa/Expositions/".$expo.".expo");
		if (!$expo_file) oyster_log("ERROR", "Fehler beim Lesen der Ausstellung.", "MonaLisa Exposition");
		$expo_files = sqlite_array_query($expo_file, "SELECT * FROM expo WHERE (type='file' OR type='folder')");
		$expo_desc = sqlite_array_query($expo_file, "SELECT exhibit FROM expo WHERE (type='desc')");
		$expo_date = sqlite_array_query($expo_file, "SELECT exhibit FROM expo WHERE (type='date')");
		$expo_tiny = sqlite_array_query($expo_file, "SELECT exhibit FROM expo WHERE (type='tiny')");
		$template->_template_assign("NAME", $expo_desc[0]["exhibit"]);
		$template->_template_assign("DATUM", date("d.m.y", $expo_date[0]['exhibit'])." um ".date("H:i", $expo_date[0]['exhibit']));
		$template->_template_assign("COUNT", count($expo_files));
		$template->_template_assign("TINYURL", $expo_tiny[0]["exhibit"]);
		$template->_template_assign("CAPTION_EXPO2", sprintf(
			(string)$language->msgs->value_3,
				$expo_desc[0]["exhibit"],
				date("d.m.y", $expo_date[0]['exhibit']),
				date("H:i", $expo_date[0]['exhibit'])));
		$template->_template_assign("CAPTION_EXPO3", sprintf(
			(string)$language->msgs->value_4,
				count($expo_files)));
		$items = array();
		$bg_color = 1;
		foreach ($expo_files as $val){
			if (file_exists($val["exhibit"]) AND is_file($val["exhibit"])){
				if ($bg_color == 1){
					$items["BG_COLOR"] = "#dedede";
					$bg_color++;
				} else {
					$items["BG_COLOR"] = "#efefef";
					$bg_color = 1;
				}
				$pathinfo = pathinfo($val["exhibit"]);
				$filename = $pathinfo['basename'];
				$extension = $pathinfo['extension'];
				$filesize = oyster_filesize(filesize($val["exhibit"]));
				if (file_exists("System/Design/Icons/Filetypesupport/".$extension.".png")) {
					$items["ICON"] = $extension;
				} else {
					$items["ICON"] = "file";
				}
				$items["PATH"] = $pathinfo["dirname"];
				$items["BEZEICHNUNG"] = $filename;
				$items["SIZE"] = $filesize;
				$filemtime = date("d.m.y G:i", filemtime($val["exhibit"]));
				if (array_key_exists(strtoupper($extension), $filetypesupport)){
					$type = $filetypesupport[strtoupper($extension)];
				} else {
					$type = strtoupper($extension)."-Datei";
				}
				$items["ART"] = $type;
				$items["CHANGED"] = $filemtime;
				$items["DNLD"] = $val["exhibit"];
				$template->_template_append("ITEMS",$items);
			}
		}
	} else {
		oyster_log("ERROR", "Die Ausstellung $expo wurde nicht gefunden.", "MonaLisa Exposition");
	}
	
	sqlite_close($expo_file);
	echo $template->_template_toHTML();	
?>